//
//  UISwitch+BZTheme.m
//  MZBasic
//
//  Created by Sings on 2022/9/21.
//

#import "UISwitch+BZTheme.h"

@implementation UISwitch (BZTheme)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class           = [UISwitch class];
        Method originalmethod = class_getInstanceMethod(class, @selector(setOnTintColor:));
        Method swizzledMethod = class_getInstanceMethod(class, @selector(switchSetOnTintColor:));
        method_exchangeImplementations(originalmethod, swizzledMethod);
    });
}

- (void)switchSetOnTintColor:(UIColor *)onTintColor {
    [self switchSetOnTintColor:onTintColor];
    self.subviews[0].subviews[0].backgroundColor = BZTHEME_COLOR(skin_switch_off_bg_color);
    if (@available(iOS 13.0, *)) {
        
    } else {
        self.subviews[0].subviews[0].layer.cornerRadius = self.bounds.size.height*0.5;
        self.subviews[0].subviews[0].layer.maskedCorners = kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner;
    }
}

@end
